﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;
using System.Collections.Generic;

public partial class admin_UserInfoList : System.Web.UI.Page
{
    private static List<User> list = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Message.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 76)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ShowUserInfo")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "window.showModalDialog ('UserInfo.aspx?loginName=" + e.CommandArgument.ToString() + "', '','status:no;center:yes;scroll:no;resizable:no;help:no;dialogWidth:550px;dialogHeight:340px');", true);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TarreOA.TarreOAModels.User user = new User();
        UserInfo userInfo = new UserInfo();
        if (txtLoginName.Text != null && txtLoginName.Text != "")
        {
            user.LoginName = txtLoginName.Text.Trim();
        }
        if (txtUserName.Text != null && txtUserName.Text != "")
        {
            user.UserName = txtUserName.Text.Trim();
        }
        if (txtJoinTime.Text != null && txtJoinTime.Text != "")
        {
            userInfo.JoinTime = Convert.ToDateTime(txtJoinTime.Text);
        }
        if (ddlSection.SelectedValue != "0")
        {
            Section section = new Section();
            section.SectionId = Convert.ToInt32(ddlSection.SelectedValue);
            user.Section = section;
        }
        if (ddlAcademicCertificate.SelectedValue != "0")
        {
            userInfo.AcademicCertificate = Convert.ToInt32(ddlAcademicCertificate.SelectedValue);
        }
        list = UserManager.FindBlurUserInfo(user, userInfo, Convert.ToInt32(ddlState.SelectedValue));
        GridView1.DataSource = list;
        GridView1.DataSourceID = null;
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = list;
        GridView1.DataBind();
    }
}
